package com.lht.leetcodeDemo;

import org.junit.Test;

/**
 * @author Eric
 * @version 1.0
 * @date 2019-05-28
 */
public class Numberof1Bits {

    @Test
    public void test() {
        System.out.println(new Numberof1Bits().hammingWeight(0B11111111111111111111111111111101));
    }

    public int hammingWeight(int n) {
        int sum = 0;
        for (int i = 0; i < 32; i++) {
            System.out.print(n & 0x1);
            if ((n & 0x1) == 1) {
                ++sum;
            }
            n>>=1;
        }
        System.out.println();
        return sum;
    }
}
